package org.jeecg.modules.meter.mapper;

import com.baomidou.mybatisplus.annotation.SqlParser;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.entity.meter.Meter;
import org.jeecg.entity.meter.MeterChargeInfo;
import org.jeecg.entity.meter.MeterRead;
import org.jeecg.entity.meter.ReceiveList;
import org.jeecg.model.meter.reqvo.MeterDayReportReqVo;
import org.jeecg.model.meter.resvo.MeterUseListRespVo;
import org.jeecg.model.meter.resvo.MeterUseReportRespVo;
import org.jeecg.modules.message.entity.SysMessage;
import org.jeecg.vo.meter.FloorResVo;
import org.jeecg.vo.meter.MeterSmsRespVo;
import org.jeecg.vo.meter.roomResVo;

import java.util.List;

/**
 * @Description: 水电表基础信息
 * @Author: jeecg-boot
 * @Date:   2020-11-20
 * @Version: V1.0
 */
public interface MeterMapper extends BaseMapper<Meter> {

    List<Meter> findPage(Page<Meter> page,@Param("meter") Meter meter);

    @SqlParser(filter = true)
    Meter getSelfById(String meterId);
    @Update("UPDATE meter set use_status = #{state},create_by=#{user.realname},create_time = now() where id =#{meterId} and del_flag='0'")
    Integer updateStatus(@Param("meterId") String meterId, @Param("state") Integer state, @Param("user") LoginUser user);

    List<ReceiveList> getAddressList(@Param("meterId") String meterId);

    List<MeterRead> historyRead(@Param("meterId") String meterId);
    @SqlParser(filter = true)
    List<Meter> queryMeterList(@Param("ids") List<String> asList);

    @SqlParser(filter = true)
    void refreshWarningStatus(@Param("meterList") List<Meter> meterStatusList);
    @SqlParser(filter = true)
    void updateSwitchStatus(@Param("bean") Meter meter);

    Integer deleteByMeterId(@Param("meterId") String id);
    @Select("select name from base_project where id =#{projectId} AND del_flag = '0'")
    String queryProjectName(@Param("projectId") String projectId);
    @Select("select id from base_floor where project_id =#{projectId} AND name = #{floorName} and del_flag='0'")
    String queryFloorName(@Param("projectId") String projectId,@Param("floorName") String trim);
    @Select("select id from base_room where floor_id =#{floorId} AND name =#{roomName} and del_flag='0'")
    String queryRoomName(@Param("floorId") String floorId,@Param("roomName") String trim);

    List<Meter> findByIds(@Param("ids") List<String> ids);

    int updateSyncStatus(@Param("id") String id,@Param("meterKey") String meterKey);
    @SqlParser(filter = true)
    List<MeterUseListRespVo> queryUseList();

    List<MeterUseReportRespVo> findGroupList(@Param("reportReq") MeterDayReportReqVo meterDayReportReqVo);

    @SqlParser(filter = true)
    List<Meter>  findMeterList();

    String queryTenantId(@Param("projectId") String projectId);
    @SqlParser(filter = true)
    List<MeterSmsRespVo> queryMeterSms();
    @SqlParser(filter = true)
    SysMessage querySmsIsSend(@Param("meterId") String meterId);

    List<roomResVo> queryRoomList(@Param("projectId") String projectId);

    List<FloorResVo> queryFloorList(@Param("projectId")String projectId);

    List<String> queryFloorIdList(@Param("meterId") String meterId);

    List<String> queryRoomIdList(@Param("meterId")String meterId);

    Integer collectorAddressBatch(@Param("meterIds") List<String> meterIds,@Param("collector") String collector);

    List<String> getCollectorAddress(@Param("meterIds") List<String> meterIds);
    @Select("select count(1) from meter where meter_code = #{meterCode} and del_flag ='0' ")
    Integer queryCountMeterCode(@Param("meterCode") String meterCode);

    Integer updates(@Param("meter") Meter meter);
    @SqlParser(filter = true)
    Integer queryMeterUseCount();

    void saveMeterMonthUse(@Param("meterUse") List<MeterUseListRespVo> meterUseListRespVos);

    @SqlParser(filter = true)
    @Select("select * from meter_use")
    List<MeterUseListRespVo> getMeterMonthUse();

    void updateMonthMeterUse(@Param("meterNewUse") List<MeterUseListRespVo> meterUseListRespVos);

    List<MeterChargeInfo> getMeterPayRecord(@Param("meterId") String meterId);
}
